package com.bitbank.smartdevice.ui.base

import android.support.annotation.StringRes
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import com.bitbank.smartdevice.manager.QDUpgradeManager
import com.qmuiteam.qmui.arch.QMUIFragment
import com.qmuiteam.qmui.util.QMUIDisplayHelper

/**
 *  Date：2018/12/11
 *  Author：xulee
 *  Desc：
 */
abstract class BaseFragment : QMUIFragment() {

    private lateinit var mView: View

    override fun backViewInitOffset(): Int {
        return QMUIDisplayHelper.dpToPx(100)
    }


    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (hidden) {   // 不在最前端显示 相当于调用了onPause();
            return
        } else {  // 在最前端显示 相当于调用了onResume();
            //网络数据刷新
        }
    }

    override fun onResume() {
        super.onResume()
        QDUpgradeManager.getInstance(context!!).runUpgradeTipTaskIfExist(activity!!)
    }

    override fun onCreateView(): View {
        mView = LayoutInflater.from(context).inflate(getLayoutID(), null)
        initView(mView)
        return mView
    }

    abstract fun getLayoutID(): Int
    abstract fun initView(v: View)

    open fun getV(): View = mView

    open fun toast(stringId: String) {
        Toast.makeText(context, stringId, Toast.LENGTH_LONG).show()
    }

    open fun toast(@StringRes stringRes: Int) {
        Toast.makeText(context, stringRes, Toast.LENGTH_LONG).show()
    }
}